package com.bsoft.hospitalchs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bsoft.hospitalchs.R;
import com.bsoft.hospitalchs.model.SearchResList;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 泅渡者
 * Created on 2017/7/18.
 */

public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder> {
    private Context context;
    private List<SearchResList.BodyBean> dataList;

    public interface OnItemClickLitener {
        void onItemClick(View view, int potison);
    }

    private ChildCaseAdapter.OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(ChildCaseAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;

    }

    public SearchAdapter(Context context, List<SearchResList.BodyBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_layout_search, parent, false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        SearchResList.BodyBean bodyBean = dataList.get(position);
        holder.tvAccount.setText(bodyBean.getCARDNO());
        holder.tvName.setText(bodyBean.getPERSONNAME());
        holder.tvGender.setText(bodyBean.getSEXNAME());
        holder.tvDoctor.setText(bodyBean.getBIRTHDAY());
        holder.tvYue.setText(bodyBean.getADVANCECOST() + "");
        holder.tvDataname.setText(bodyBean.getJZJG());

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickLitener.onItemClick(holder.itemView, position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_head)
        ImageView ivHead;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.textView2)
        TextView textView2;
        @Bind(R.id.tv_gender)
        TextView tvGender;
        @Bind(R.id.tv_account)
        TextView tvAccount;
        @Bind(R.id.tv_yue)
        TextView tvYue;
        @Bind(R.id.tv_doctor)
        TextView tvDoctor;
        @Bind(R.id.tv_dataname)
        TextView tvDataname;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void addAllData(List<SearchResList.BodyBean> dataList) {
        for (SearchResList.BodyBean bodyBean : dataList) {
            this.dataList.add(bodyBean);
        }
        notifyDataSetChanged();
    }

    public void clearData() {
        this.dataList.clear();
        notifyDataSetChanged();
    }

    public SearchResList.BodyBean getCurrentItem(int position) {
        return dataList.get(position);
    }
}
